<?

class Files {

    public static $data;


    public static function import(){

    }

	public static function get_icon(){

	}

	public static function force_download($file){
		$mime = 'application/force-download';
		header('Pragma: public');  // required
		header('Expires: 0');  // no cache
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Cache-Control: private',false);
		header('Content-Type: '.$mime);
		header('Content-Disposition: attachment; filename="'.basename($file).'"');
		header('Content-Transfer-Encoding: binary');
		header('Connection: close');
		readfile($file);  // push it out
		exit();
	}

	public static function add_prefix($thumb, $prefix = "-th"){
	  $path_parts = pathinfo($thumb);

	  $f = $path_parts['dirname']."/".$path_parts['filename'] . $prefix . "." .$path_parts['extension'];
	  return $f;
	}


	public static function remove_prefix($pic){
	  $path_parts = pathinfo($pic);

	  $tmp = explode("-", $path_parts['filename']);
	  $prefix = end($tmp);

	  $path_parts['filename'] = str_replace("-".$prefix,"",$path_parts['filename']);

	  $f = $path_parts['dirname']."/".$path_parts['filename'] . "." .$path_parts['extension'];
	  return $f;
	}


    public static function make_dir($dir){

        if( !is_dir($dir) ){
            mkdir($dir);
        }
    }

    public static function open($filename){

        try{
            $fp = fopen( $filename, 'r');

            $t = "";
            while ($line = fgets ($fp)) {
                $t .= $line;
            }

            self::$data = $t;

            fclose($fp);

            return $t;

        }catch (exception $e){
            return $e;
        }

    }


    public static function save($filename, $inp = ""){

        if($inp == ""){
            $inp = $this->data;
        }

        $fp = fopen($filename, 'w+');
        fwrite($fp, $inp);
        fclose($fp);
    }

}

?>